@echo off
chcp 65001 >nul
echo 🎯 操作录制器 - 快速打包脚本
echo ================================
echo.

echo 📋 检查PyInstaller...
python -c "import PyInstaller" 2>nul
if errorlevel 1 (
    echo ❌ PyInstaller未安装，正在安装...
    python -m pip install pyinstaller
    if errorlevel 1 (
        echo ❌ PyInstaller安装失败，请手动安装
        pause
        exit /b 1
    )
    echo ✅ PyInstaller安装成功
) else (
    echo ✅ PyInstaller已安装
)

echo.
echo 🧹 清理旧文件...
if exist "build" rmdir /s /q "build"
if exist "dist" rmdir /s /q "dist"
if exist "main.spec" del "main.spec"

echo.
echo 📦 开始打包...
pyinstaller --onefile --windowed --name="操作录制器" --icon="icon_control_hover.png" --add-data="icon_control_hover.png;." --add-data="scripts;scripts" --add-data="config.json;." --hidden-import=pynput --hidden-import=pystray --hidden-import=PIL --hidden-import=tkinter --clean main.py

if errorlevel 1 (
    echo ❌ 打包失败
    pause
    exit /b 1
)

echo.
echo 📋 复制文档文件...
copy "使用说明文档.md" "dist\" >nul 2>&1
copy "开发说明文档.md" "dist\" >nul 2>&1
copy "悬浮窗使用说明.md" "dist\" >nul 2>&1
copy "系统托盘安装说明.md" "dist\" >nul 2>&1
copy "默认脚本功能说明.md" "dist\" >nul 2>&1

echo.
echo 📝 创建安装脚本...
echo @echo off > "dist\安装.bat"
echo chcp 65001 ^>nul >> "dist\安装.bat"
echo echo 🎯 操作录制器 - 安装脚本 >> "dist\安装.bat"
echo echo. >> "dist\安装.bat"
echo echo 正在创建桌面快捷方式... >> "dist\安装.bat"
echo echo. >> "dist\安装.bat"
echo set "exe_path=%%~dp0操作录制器.exe" >> "dist\安装.bat"
echo set "desktop=%%USERPROFILE%%\Desktop" >> "dist\安装.bat"
echo set "shortcut=%%desktop%%\操作录制器.lnk" >> "dist\安装.bat"
echo powershell -Command "$WshShell = New-Object -comObject WScript.Shell; $Shortcut = $WshShell.CreateShortcut('%%shortcut%%'^); $Shortcut.TargetPath = '%%exe_path%%'; $Shortcut.WorkingDirectory = '%%~dp0'; $Shortcut.IconLocation = '%%exe_path%%'; $Shortcut.Save(^)" >> "dist\安装.bat"
echo if exist "%%shortcut%%" (echo ✅ 桌面快捷方式创建成功!^) else (echo ❌ 快捷方式创建失败^) >> "dist\安装.bat"
echo echo. >> "dist\安装.bat"
echo echo 📁 程序位置: %%exe_path%% >> "dist\安装.bat"
echo echo 📋 使用说明请查看同目录下的文档文件 >> "dist\安装.bat"
echo echo. >> "dist\安装.bat"
echo pause >> "dist\安装.bat"

echo.
echo ✅ 打包完成!
echo 📁 可执行文件位置: dist\操作录制器.exe
echo 📋 运行 dist\安装.bat 可创建桌面快捷方式
echo.
pause